package com.tgb.controller;

import java.util.Random;

import javax.servlet.http.HttpServletRequest;

import org.activiti.engine.RuntimeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.tgb.entity.Approve;
import com.tgb.entity.Leave;
import com.tgb.service.AuditManager;
/**
 * 审批类controller
 * @author hejingyuan
 *
 */
@Controller
public class AuditController {

	private Logger logger = LoggerFactory.getLogger(getClass());
	
	@Autowired
	protected AuditManager auditManager;
	//运行类服务
    @Autowired
    RuntimeService runtimeService;
    

   

	/**
	 * 保存审批信息-2015年6月6日08:20:17
	 * 
	 * @param leave
	 */
	@RequestMapping(value = "approve")
	public String approve(Leave leave,RedirectAttributes redirectAttributes,HttpServletRequest request) {		
		String result = request.getParameter("result"); 
		String advice = request.getParameter("advice");
		
		Approve approve=new Approve();
		approve.setAdvice(advice);
		approve.setResult(result);
		approve.setLeave(leave);
		int id = new Random().nextInt(10);
		Long idl=new Long((long)id);
		approve.setId(idl);		
		auditManager.save(approve);
		
		redirectAttributes.addFlashAttribute("message", "业务数据已保存");	
		return "/leave/finish";
	}

	
}
